package cn.dnui_lf_705.dnui_16110100705.Fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import cn.dnui_lf_705.dnui_16110100705.Adapter.CollectAdapter;
import cn.dnui_lf_705.dnui_16110100705.R;
import cn.dnui_lf_705.dnui_16110100705.bean.GetAllUserCollectionBean;
import cn.dnui_lf_705.dnui_16110100705.listener.OnRetrofitListener;
import cn.dnui_lf_705.dnui_16110100705.model.UserModel;


/**
 * A simple {@link Fragment} subclass.
 */
public class CollectShopFragment extends BaseFragment implements OnRetrofitListener<List<GetAllUserCollectionBean>> {

    private RecyclerView collect_rv;
    public CollectAdapter adapter;
    private UserModel userModel;



    public CollectShopFragment() {
        // Required empty public constructor
    }


    @Override
    void initViews() {
        collect_rv=view.findViewById(R.id.shop_collected_list);
        collect_rv.setLayoutManager(new LinearLayoutManager(getActivity()));
    }

    @Override
    void initEvents() {

    }

    @Override
    void initData() {
        userModel = new UserModel();
        userModel.getAllUserCollection(getUser_id(),0,this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        setLayout_file(R.layout.collect_shopfragment);
        return super.onCreateView(inflater,container,savedInstanceState);
    }


    @Override
    public void onsuccess(List<GetAllUserCollectionBean> getAllUserCollectionBeans, int flag) {
        adapter = new CollectAdapter(context,getAllUserCollectionBeans);
        collect_rv.setAdapter(adapter);
    }

    @Override
    public void onFailure(String string) {
         Toast.makeText(getActivity(),"网络错误",Toast.LENGTH_SHORT).show();
    }
}
